package homework10_String;

import java.util.Random;

/**
 * @author admin
 * @version 1.0
 * @date 2024-04-02 22:49
 */

public class Test02 {
    //键盘输入任意字符串，打乱里面的内容
    public static void main(String[] args) {
        String str = "abcdefg";
        char[] arr = str.toCharArray();
        int length=arr.length;
        for (int i = 0; i < arr.length; i++) {
           char temp;
           temp=arr[i];
           int randomIndex=scrambleNumber(length);
           arr[i]=arr[randomIndex];
           arr[randomIndex]=temp;
        }
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);
        }
        System.out.println(sb.toString());
    }

    public static int scrambleNumber(int length) {
        Random random=new Random();
        int randomNumber= random.nextInt(length)+0;
        return randomNumber;
    }
}
